//
//  SEInquiryInfo.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/19.
//

import Foundation
import HandyJSON

/// 问诊流程状态
/// 0初始待支付,1支付成功后台发起,2医生同意,3患者收到医生同意,4医生结束发,5患者同意,6医生拒绝,7患者拒绝结束,8患者取消,9已评价
enum SEInquiryChangeStatus: String, HandyJSONEnum, Codable {
    case waitPay = "0", waitConfirm = "1", confirming = "2", confirmed = "3", waitEnd = "4", confirmEnd = "5", rejected = "6", rejectEnd = "7", cancel = "8", commented = "9"
    
    var hudMessage: String? {
        switch self {
        case .confirming: return "医生已经接诊"
        case .rejected:   return "医生拒绝接诊"
        case .waitEnd:    return "医生发起结束问诊"
        default: return nil
        }
    }
    
    var statusText: String? {
        switch self {
        case .confirmEnd: return "已同意"
        case .rejectEnd:  return "已拒绝"
        default:          return nil
        }
    }
    
    var statusTextColor: UIColor? {
        switch self {
        case .confirmEnd: return Asset.main.color
        case .rejectEnd:  return Asset.warn.color
        default:          return nil
        }
    }
    
    var statusTextHidden: Bool {
        switch self {
        case .waitEnd:   return true
        case .confirmEnd,
             .rejectEnd: return false
        default:         return false
        }
    }
    
    var message: String? {
        switch self {
        case .waitEnd:    return "[结束问诊确认]"
        case .confirmEnd: return "[已确认结束]"
        case .rejectEnd:  return "[已确认继续]"
        default: return nil
        }
    }
}

/// 1 - 导诊 2 - 线上问诊
enum SEInquiryType: Int, HandyJSONEnum, Codable {
    case guide = 1
    case online
    
    var chatType: SEChatType {
        switch self {
        case .guide: return .gudieInquiry
        case .online: return .onlineInquiry
        }
    }
    
    var msgType: String {
        switch self {
        case .online:  return "single"
//        case .group:    return "group"
//        case .push:     return "push"
//        case .sms:      return "sms"
        case .guide: return "guidance"
        }
    }
    
    var msgFromType: SEChatMessageFromType {
        return .private
    }
}

/// 问诊、导诊状态
///（0初始待支付，1未就诊，2就诊中，3已结束，4用户已取消，5医生已拒绝）
enum SEInquiryStatus: Int, HandyJSONEnum, Codable {
    case waitPay = 0, reserve, processing, finish, cancel, doctorReject, unknown = -1

    var title: String {
        switch self {
        case .waitPay: return "待支付"
        case .reserve: return "待接诊"
        case .processing: return "进行中"
        case .finish: return "已结束"
        case .doctorReject: return "医生拒绝"
        case .cancel: return "已取消"
        case .unknown: return "未知状态"
        }
    }

    var titleColor: UIColor {
        switch self {
        case .waitPay: return UIColor(hex: "#F7B500")
        case .reserve, .processing: return UIColor(hex: "#4ABC90")
        default: return Asset.textGrayLightest.color
        }
    }
}

enum SEPatientFileAuthorizedStatus: String, HandyJSONEnum, Codable {
    case unauthorized = "1", authorized = "2", refuse = "3"
    
    var buttonHidden: Bool {
        switch self {
        case .unauthorized: return false
        default:            return true
        }
    }
    
    var statusText: String? {
        switch self {
        case .unauthorized: return nil
        case .authorized:   return "已同意"
        case .refuse:       return "已拒绝"
        }
    }
    
    var statusTextColor: UIColor {
        switch self {
        case .unauthorized: return UIColor.clear
        case .authorized:   return Asset.main.color
        case .refuse:       return Asset.warn.color
        }
    }
}

/// 就诊信息
struct SEInquiryInfo: HandyJSON, Codable {
    /// 1-导诊 2-问诊
    var type: SEInquiryType = .guide
    
    var id: String?
    var creator: String?        // 发送者id
    var creatorName: String?    // 发送者名称
    var createTime: String?
    var updateTime: String?
    var `operator`: String?
    var isDeleted: Int = 0
    
    var patientId: String?
    var patientName: String?
    var patientSex: Int = 0
    var patientAge: String?
    var patientPhone: String?
    var patientIdcard: String?

    var hospitalName: String?
    var hospitalId: String?

    var doctorId: String?
    var doctorName: String?
    var doctorSex: Int = 2
    var doctorSexName: String?
    var deptName: String?
    var jobTitle: String?
    var receiver: String?       // 接收者id
    var receiverName: String?   // 接收者名称
    var illness: String?
    var isAllergic: Int = 1
    var allergicContent: String?
    var pastHistory: String?
    var urlRelation: String?
    var status: SEInquiryStatus = .unknown
    var dealStatus: SEInquiryChangeStatus = .waitPay
    var unReadCount: Int = 0
    var lastReadTime: String?
    var msgType: SEChatMessageType = .text
    var content: String?
    var picList: [SEUploadFileModel]?
    
    var result: String?                 // 诊断结果
    var proposal: String?               // 医嘱意见
    
    var userPhoto: String?
    var otherPhoto: String?
    
    var orderId: String?

    /// 问诊费用
    var amount: Double = 0

    /// 是否有审核通过的处方 0 - 没有 其他 - 有
    var isPrescription: Int = 0

    /// 评论id
    var commentId: String?
    /// 评论分数
    var rank: Int = 0
    
    var authorizationStatus: SEPatientFileAuthorizedStatus = .unauthorized
    
    var leftTime: Int = 0   // 结束倒计时（毫秒）
}

struct SEGuideInquiryModel: HandyJSON {
    var id: String?     // 客服id
    var name: String?   // 客服名称
    var bisId: String?  // 导诊id
    var status: Int = 0 // 是否处于导诊中;1是，2否
}
